package handlers;

import java.util.Random;

import main.MainMap;
import people.Character;
import constants.Colors;

public class MoveCharacterHandler extends Colors {

	public static void handle(boolean up, boolean down, boolean left,
			boolean right, String[] args) {
		Character c = Character.c;
		MainMap.mainMap.map[c.x][c.y].setIcon(null);
		if (MainMap.mainMap.map[c.x][c.y].getBackground() != BACKGROUND_COLOR) {
			MainMap.mainMap.map[c.x][c.y].setBackground(BACKGROUND_COLOR);
		}
		if (storage.EnemyStorage.findEnemyinXY(c.x, c.y) != null) {
			MainMap.mainMap.map[c.x][c.y].setBackground(MOB_COLOR);
		}
		if (up) {
			if (c.x == 0) c.x = 9;
			else c.x--;
		}
		else if (down) {
			if (c.x == 9) c.x = 0;
			else c.x++;
		}
		else if (left) {
			if (c.y == 0) c.y = 9;
			else c.y--;
		}
		else if (right) {
			if (c.y == 9) c.y = 0;
			else c.y++;
		}
		//MainMap.mainMap.map[c.x][c.y].setBackground(PLAYER_COLOR);
		if (c.job == 1) {
			MainMap.mainMap.map[c.x][c.y].setIcon(WIZARD_ICON);
		}
		else if (c.job == 2) {
			MainMap.mainMap.map[c.x][c.y].setIcon(WARRIOR_ICON);
		}
		else if (c.job == 3) {
			MainMap.mainMap.map[c.x][c.y].setIcon(THIEF_ICON);
		}
		else if (c.job == 4) {
			MainMap.mainMap.map[c.x][c.y].setIcon(ARCHER_ICON);
		}
		if (storage.EnemyStorage.findEnemyinXY(c.x, c.y) != null) {
			MainMap.mainMap.map[c.x][c.y].setBackground(MOB_AND_PLAYER_ON_SAME_SPOT);
		}
		Random random = new Random();
		int rand = random.nextInt(100);
		if (rand > constants.GeneralConstants.MOB_ENCOUNTER_PERCENT) {
				EnemySpawnHandler.handle();
		}
	}
}
